//
//  ToolViewViewController.m
//  IWaneHome
//
//  Created by hwd on 印度历1938/3/22.
//  Copyright © 印度历1938年 hwd_zlg. All rights reserved.
//

#import "ToolViewVC.h"

@implementation ToolViewVC

//弹窗
+(void)addAlterViewController:(NSString *)msg Controller:(UIViewController *)controller
{
 
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:  UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [controller presentViewController:alert animated:true completion:nil];
}
//pop弹窗
+(void)addPopAlterViewController:(NSString *)msg Controller:(UIViewController *)controller
{
    [IQKeyboardManager sharedManager].enable = NO;
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [controller.navigationController popViewControllerAnimated:YES];
    }]];
    //弹出提示框；
    [controller presentViewController:alert animated:true completion:nil];
}
//Key弹窗
+(void)addKeyAlterViewController:(NSString *)msg Controller:(UIViewController *)controller
{
    [IQKeyboardManager sharedManager].enable = NO;
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:  UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //点击按钮的响应事件；
        [IQKeyboardManager sharedManager].enable = YES;
    }]];
    //弹出提示框
    [controller presentViewController:alert animated:true completion:nil];
}
+(UILabel *)addLineLab:(CGRect)cg
{
    UILabel *label = [[UILabel alloc]initWithFrame:cg];
    label.backgroundColor = LineColor;
    return label;
}
+(UILabel *)addCellLineLab:(CGRect)cg
{
    UILabel *label = [[UILabel alloc]initWithFrame:cg];
    label.backgroundColor = LineColor;
    return label;
}
+ (float) heightForTextViewWithText: (NSString *) strText{
    CGSize constraint = CGSizeMake(SCREENW-50*screenW_6, CGFLOAT_MAX);
    CGRect size = [strText boundingRectWithSize:constraint
                                        options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                     attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]}
                                        context:nil];
    float textHeight = size.size.height + 30.0;
    
    return textHeight;
}
+(BOOL)isNotNullStr:(id)DataStr
{
    if ([DataStr isEqual:@""] || [DataStr isKindOfClass:[NSNull class]] || [DataStr isEqual:@"<null>"] || DataStr == NULL) {
        return NO;
    }
    return YES;
}
+(NSString *)ChangeData:(NSString *)str IntType:(NSString *)IntType OutType:(NSString *)outType
{
    if (![self isNotNullStr:str]) {
        return @"";
    }
    NSDateFormatter *dateFormatterYear = [[NSDateFormatter alloc] init];
    [dateFormatterYear setDateFormat:IntType];
    NSDate *time = [dateFormatterYear dateFromString:str];
    [dateFormatterYear setDateFormat:outType];
    NSString *YearDaySrt = [dateFormatterYear stringFromDate:time];
    
    return YearDaySrt;
}
+(NSString *)ChangeTimeYearMD:(NSDate *)date Type:(NSString *)outType//返回年月日
{
    if (![self isNotNullStr:date]) {
        return @"";
    }
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:outType];
    NSString *nowTime = [formatter stringFromDate:date];
    return nowTime;
}
+(id)getNotNullStr:(id)DataStr
{
    if ([DataStr isEqual:@""] || [DataStr isKindOfClass:[NSNull class]] || [DataStr isEqual:@"<null>"] || DataStr == NULL || !DataStr) {
        return @"";
    }
    return DataStr;
}
//时间Dete
+ (NSDate *)getTimeDate:(NSString *)Time IntType:(NSString *)type
{
    NSDateFormatter *date=[[NSDateFormatter alloc] init];
    [date setDateFormat:type];
    NSDate *d1 = [date dateFromString:[NSString stringWithFormat:@"%@",Time]];
    NSTimeInterval timeInterval=[d1 timeIntervalSince1970]*1;
    NSDate *dateTime = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    return dateTime;
}

+ (NSString *)getTimeStr:(NSString *)time
{
    float timeFloat = [time floatValue];
    NSString *timeStr;
    if (timeFloat>3600) {
        timeStr = [NSString stringWithFormat:@"%.1f小时",timeFloat/3600];
    }else if (timeFloat>60)
    {
        timeStr = [NSString stringWithFormat:@"%.1f分钟",timeFloat/60];
    }else
    {
        timeStr = [NSString stringWithFormat:@"%.0f秒",timeFloat];
    }
    
    return timeStr;
}

@end
